package com.zsj.comminlibrary.util;


import android.os.Handler;
import android.os.HandlerThread;

/**
 * Created by L on 2016/6/24.
 */
public class WorkHandler {

    private static Handler sHandler;

    public static void run(Runnable runnable)
    {
        if(sHandler ==null)
        {
            HandlerThread handlerThread = new HandlerThread("worker");
            handlerThread.start();
            sHandler = new Handler(handlerThread.getLooper());
        }
        sHandler.post(runnable);
    }
    public static void cancel(Runnable runnable){
        if(sHandler !=null)
            sHandler.removeCallbacks(runnable);
    }
    public static void cancelAll(){
        if (sHandler != null) {
            sHandler.removeCallbacksAndMessages(null);
        }
    }
}
